package com.dujiu.leetcode.slidingWindow.fixed_lengthSlidingWindow;

import java.util.Arrays;

public class P1652 {
    public int[] decrypt(int[] code, int k) {
        int n = code.length;
        int[] array = new int[n];
        if (k == 0){
            return array;
        }
        for (int i = 0;i < n;i++){
            int sum = 0;
            if (k > 0){
                for (int j = 1; j <= k; j++) {
                    sum += code[(i+j)%n];
                }
            }else {
                for (int j = 1; j <= -k; j++) {
                    sum += code[(i-j+n)%n];
                }
            }
            array[i] = sum;
        }
        return array;
    }

    public static void main(String[] args) {
        int[] code = {5,7,1,4};
        P1652 p = new P1652();
        System.out.println(Arrays.toString(p.decrypt(code, 3)));
    }
}
